package org.example.os.synchronous.producer_comsumer;

public class ProducerConsumerTest {
    public static void main(String[] args) throws InterruptedException {
        // WaitNotifyAllAchievement pc = new WaitNotifyAllAchievement(5);
        // LockConditionAchievement pc = new LockConditionAchievement(5);
        BlockingQueueAchievement pc = new BlockingQueueAchievement(5);
        // SemaphoreAchievement pc = new SemaphoreAchievement(5);
        // ExchangerAchievement pc = new ExchangerAchievement();
        // PipedStreamAchievement pc = new PipedStreamAchievement();

        Thread producer = new Thread(() -> {
            try {
                pc.produce();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        Thread consumer = new Thread(() -> {
            try {
                pc.consume();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        producer.start();
        consumer.start();

        // 运行一段时间后停止
        Thread.sleep(10000);

//        if (pc instanceof ExchangerExample || pc instanceof PipedStreamExample) {
//            ((ExchangerExample)pc).stop();
//        }

        producer.interrupt();
        consumer.interrupt();

    }
}
